const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

/**
 * 学生分析报告模型
 */
const StudentAnalysis = sequelize.define('StudentAnalysis', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  student_id: {
    type: DataTypes.STRING(20),
    allowNull: false,
    unique: true,
    comment: '学生准考证号'
  },
  student_name: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '学生姓名'
  },
  class_name: {
    type: DataTypes.STRING(50),
    allowNull: true,
    comment: '班级名称'
  },
  analysis_report: {
    type: DataTypes.TEXT('long'),
    allowNull: false,
    comment: 'AI分析报告内容'
  },
  exam_count: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '分析时包含的考试次数'
  },
  last_exam_date: {
    type: DataTypes.DATE,
    allowNull: true,
    comment: '最后一次考试日期'
  },
  created_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    comment: '创建时间'
  },
  updated_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    comment: '更新时间'
  }
}, {
  tableName: 'student_analysis',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  indexes: [
    {
      fields: ['student_id']
    },
    {
      fields: ['student_name']
    },
    {
      fields: ['updated_at']
    }
  ]
});

module.exports = StudentAnalysis;
